<?php
/**
 * Created by PhpStorm.
 * User: silov
 * Date: 15/6/24
 * Time: 15:13
 */
namespace Home\Model;
use Think\Cache\Driver\Redis;
use Think\Model;
class UserModel extends Model {
    protected $tableName = "user";

    /**
     * @var 密码加密key
     */
    private $passKey;

    /**
     * @var string Api token redis key Pre_Uhash
     */
    private $tokenRedis = "ApiUserToken_";

    /**
     * 初始化密码加密算法key
     */
    protected function _initialize()
    {
        $this->passKey = md5("lOgInKeY!@#$Ω≈çç√∫");
    }

    /**
     * @param  string $username 用户名
     * @param  string $mdpass 前端md5加密明文密码的值
     * @return string 最终存储的密码
     */
    private function getPassword($username, $mdpass)
    {
        $tmp = [
            'u' => $username,
            'p' => $mdpass
        ];

        ksort($tmp);

        return md5( base64_encode( http_build_query($tmp).$this->passKey ) );
    }
}